package com.czl.module_main.adapter

import android.os.Bundle
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.czl.base.binding.command.BindingCommand
import com.czl.base.binding.command.BindingConsumer
import com.czl.base.config.AppConstants
import com.czl.base.data.bean.NoticeListBean
import com.czl.module_main.R
import com.czl.module_main.databinding.ItemNoticeBinding
import com.czl.module_main.fragment.HomeFragment

/**
 *
 * @Description:
 * @Author: XCH
 * @CreateDate: 2022/1/12 10:39
 */
class NoticeAdapter(private val fragment: HomeFragment) :
    BaseQuickAdapter<NoticeListBean.Record, BaseDataBindingHolder<ItemNoticeBinding>>(
        R.layout.item_notice
    ) {

    override fun convert(holder: BaseDataBindingHolder<ItemNoticeBinding>, item: NoticeListBean.Record) {
        holder.dataBinding?.apply {
            data = item
            adapter = this@NoticeAdapter
            executePendingBindings()
        }
    }

    fun getType(type:Int):String{
        return when(type){
            1->"物业公告"
            2->"便民服务"
            3->"版本更新"
            else->""
        }
    }
    val onItemClick: BindingCommand<Any> = BindingCommand(BindingConsumer {
        if (it is NoticeListBean.Record){
            fragment.startContainerActivity(
                AppConstants.Router.Activities.F_ACTIVITIES_BULLENTIN_DETAIL,
                Bundle().apply {
                    putInt(
                        AppConstants.BundleKey.BULLENTIN_ID,
                        it.id
                    )
                })
        }
    })
}